//
//  AreaPickerViewController.m
//  QTZ
//
//  Created by ski on 2017/9/11.
//  Copyright © 2017年 ski. All rights reserved.
//

#import "AreaPickerViewController.h"
#import "PSCityPickerView.h"

@interface AreaPickerViewController ()<PSCityPickerViewDelegate>
{
    NSString *_province;
    NSString *_city;
    NSString *_area;
}
@property (nonatomic, strong) PSCityPickerView *pickView;

@property (nonatomic, strong) NSString *selectString;

@end

@implementation AreaPickerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self layoutView];
    [self initData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self animationWithComplete:NO];
}

- (void)initData
{
    _province = @"北京市";
    _city = @"北京市";
    _area = @"东城区";
}

- (void)layoutView
{
    self.selectString = nil;
    
//    weakify(self);
//    [self.view bk_whenTapped:^{
//        strongify(self);
//        [self handleCancel];
//    }];
    
    self.pickView = [[PSCityPickerView alloc] initWithFrame:CGRectMake(0, FULL_HEIGHT, FULL_WIDTH, 216 + 44)];
    self.pickView.backgroundColor = QTZ_White;
    self.pickView.cityPickerDelegate = self;
    [self.view addSubview:self.pickView];
}

- (void)animationWithComplete:(BOOL)complete
{
    if (!complete) {//进入
        
        [UIView animateWithDuration:.3 animations:^{
            self.pickView.bottom = FULL_HEIGHT;
        }];
        
    } else {//退出
        [UIView animateWithDuration:.3 animations:^{
            self.pickView.top = FULL_HEIGHT;
        }];
    }
}

- (void)handleCancel
{
    [self animationWithComplete:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)handleDone
{
    if (self.handleDoneComplete) {
        self.handleDoneComplete(_province, _city, _area);
    }
    [self handleCancel];
}

#pragma mark - PSCityPickerViewDelegate
- (void)cityPickerView:(PSCityPickerView *)picker
    finishPickProvince:(NSString *)province
                  city:(NSString *)city
              district:(NSString *)district
{
    _province = province;
    _city = city;
    _area = district;
}


@end
